var dictTypeEditCtrl  = new XFApp.client();

XFApp.client.prototype.dictTypeEdit = {
		successCode : 10000,	
		urlItems : {
			updateDictTypeURL: basePath+"/dict/updateDictType",
		},	
		
		updateDictType : function (){	
			
			var params = {
				dicttypeid:$("#hiddenId").val(),	
				dicttypename : $("#dicttypename").val(),
				dicttypedesc : $("#dicttypedesc").val(),	
				dicttypecode : $("#dicttypecode").val(),
				dictTempModelValue : $("#dictTempModelValue").val(),
				dictTempModelName : $("#dictTempModelName").val(),
				modifyType : $("#modifyType").attr("data-id"),
			};
			
			$.ajax ({
				url :_this.urlItems.updateDictTypeURL,
				data : params,
				dataType : "json",
				type : 'post',
				success : function(data) {
					if(data.code == _this.successCode){						
						window.webDialogUtil.alert("提示",data.msg);	
		        	}else{
		        		
		        		window.webDialogUtil.alert("提示",data.msg);		        		
		        	}
				}
			});			
		},		
		
		initSelect : function (){
			
			$("#modifyType").bsSuggest({
				idField: "dictCode",  
				keyField: "dictName",
				effectiveFields :["dictCode","dictName"],
				effectiveFieldsAlias:{dictCode:"编码",dictName:"名称"},
		        data: {
		           'value':modifyTypes
		        }
		   });
			
		},
		
		
		traslate :function(){
			
			var modifyType = $("#modifyType").val();
			
			for(index in modifyTypes){
				var type = modifyTypes[index];
				if(type.dictCode == modifyType){
					return type.dictName ;
				}
			}
			return  "未知类型("+modifyType+")";
		},		
		
		event : function(){
			_this = this;			
			$("#submitBtn").on("click",function(){
				if($("#editForm").validate().form()){
					dictTypeEditCtrl.dictTypeEdit.updateDictType();
				}
			});
			//表单验证
			_this.formValidate();
			
			var type = _this.traslate();
			
			$("#modifyType").val(type);
		},
		
		formValidate : function(){
			$("#editForm").validate({
		        rules: {
		        	dicttypename: "required",
		        	dicttypecode: "required",
		        	dictTempModelValue: "required",
		        	modifyType:"required"
				  },
				 messages: {
					 dicttypename: "请填写简称",
			         dicttypecode: "请填写编码",
			         dictTempModelValue: "请填写类型",
			         modifyType:"请选择是否允许修改"
			         }
		    });
			$("#editForm").validate();
		},
};


$(function(){
	dictTypeEditCtrl.dictTypeEdit.event();
	dictTypeEditCtrl.dictTypeEdit.initSelect();
});